<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
	<meta charset="UTF-8">
	<title>旭科生产管理开放平台</title>
	<link rel="icon" th:href="@{/static/console/common/images/favicon.ico}">
	<link th:href="@{/static/console/assets/css/bootstrap.min.css}" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" th:href="@{/static/console/common/layui/css/layui.css}">
	<link th:href="@{/static/console/css/system/login.css}" rel="stylesheet" />
</head>

<body>
<div class="loginBg">
	<img src="/static/console/img/login_bg.jpg" alt="" />
</div>
<input th:value="${redirectUri}" class="redirectUri" style="display: none"/>
<input th:value="${agentId}" class="agentId" style="display: none"/>
<input th:value="${orgName}" class="orgName" style="display: none"/>
<div class="loginForm user-form">
	<div class="loginTitle">
		<h1 class="title-name">旭科生产管理平台</h1>
	</div>
	<form class="layui-form">
		<div class="layui-form-item">
			<input class="layui-input" name="username" placeholder="请输入用户名或手机号" lay-verify="required|username" type="text" autocomplete="off">
		</div>
		<div class="layui-form-item">
			<input class="layui-input" name="password" placeholder="请输入登录密码" lay-verify="required" type="password" autocomplete="off">
		</div>
		<div class="layui-form-item form_code">
			<input class="layui-input layui-form-danger validCode" name="code" placeholder="请输入验证码" lay-verify="required" type="text" autocomplete="off">
			<div class="code"><img src="/console/auth/code?v=032&type=1&s=22" width="116" height="36"></div>
		</div>
		<button class="layui-btn login_btn" lay-submit lay-filter="login">登录</button>
		<a class="layui-btn qrcode_btn">扫码登录</a>
	</form>
</div>
<div class="codeForm">
<!--	<div class="codeTitle">-->
<!--		<h1>企业微信扫码登录</h1>-->
<!--	</div>-->
	<form class="layui-form">
		<div class="code-box" id="wx_reg">
<!--			<iframe src="https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=wwd85ae41a2d988bc8&agentid=1000011&redirect_uri=http://surker.chixugroup.com/console/login&state=8A2446C7FCEED80FE79AC1CE87ACB8CE&type=jssdk"/>-->
			<img src="/static/console/img/login_code.png"/>
		</div>
<!--		<div class="layui-form-item form_code">-->
<!--			<span class="layui-btn tip-span">请使用企业微信扫描二维码登录</span>-->
<!--		</div>-->
		<a class="layui-btn user_btn">密码登录</a>
	</form>
</div>
</body>
<script th:src="@{/static/console/assets/js/jquery-3.2.1.min.js}"></script>
<script th:src="@{/static/console/assets/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/static/console/common/layui/layui.all.js}"></script>
<script type="text/javascript" src="https://wwcdn.weixin.qq.com/node/wework/wwopen/js/wwLogin-1.2.4.js"></script>
<script type="text/javascript" charset="utf-8">
	$(function () {
		if (isOS()) {
			window.location.href = '/cloud/index';
		}
		var orgName = $('.orgName').val();
		if (orgName != null && orgName != '') {
			$('.title-name').html(orgName + '生产管理平台(ERP)');

		}
	});

	function isOS(){
		var os = new Array("Android","iPhone","Windows Phone","iPod","BlackBerry","MeeGo","SymbianOS");  // 其他类型的移动操作系统类型，自行添加
		var info = navigator.userAgent;
		var len = os.length;
		for (var i = 0; i < len; i++) {
			if (info.indexOf(os[i]) > 0){
				return true;
			}
		}
		return false;
	}
	var uid = -1;
	var redirectUri = $('.redirectUri').val();
	var agentId = $('.agentId').val();
	var wwLogin = new WwLogin({
		"id": "wx_reg",
		"appid": "wwd85ae41a2d988bc8",
		"agentid": agentId,
		"redirect_uri": redirectUri + "/console/index&state=8A2446C7FCEED80FE79AC1CE87ACB8CE&type=jssdk",
		"state": "",
		"href": "",
		"lang": "zh",
	});

	layui.use('form', function() {

		var form = layui.form,
				$ = layui.jquery,
				layer = layui.layer;

		$(".loginForm").hide();
		$(".codeForm").show();
		/**密码登录按钮**/
		$(".user_btn").on("click", function () {
			$(".loginForm").show();
			$(".codeForm").hide();
		});

		/**扫码登录按钮**/
		$(".qrcode_btn").on("click", function () {
			console.log(1)
			$(".loginForm").hide();
			$(".codeForm").show();
		});

		//监听提交
		form.on('submit(login)', function(data) {
			var options = {
				username: data.field.username,
				password: data.field.password,
				verifyCode: data.field.code,
				osType: 3
			};
			var loading = layer.load(1);
			$.ajax( {
				url: '/console/login',
				async: true,
				dataType:'json',
				type: 'post',
				data : options,
				success: function (obj) {
					layer.close(loading);
					layer.msg(obj.msg);
					// alert(JSON.stringify(obj))
					getPicCode();
					if (obj.code == 0) {
						window.location.href = '/console/index';
					}
					console.log(obj)
				},error:function () {
					layer.msg('网络链接超时,请稍后再试！');
					layer.close(loading);
				},complete: function(XMLHttpRequest, status) {
					if(status == 'timeout') {
						layer.msg('网络链接超时,请稍后再试！');
						layer.close(loading);
					}
				}
			});

			return false;
		});
		//	更换图片验证码
		$(".code").on("click", "img", function(e) {
			e.stopPropagation();
			getPicCode();
		});

		$('.validCode').on('click', function () {
			var validCode = $('.validCode').attr('data-type');
			if (validCode == 0) {
				getPicCode();
				$('.validCode').attr('data-type', '1');
			}
		});

		//点击更换图片
		function getPicCode() {
			var urls = "/console/auth/code?v=032&type=1&" + new Date().getTime();
			$(".code img").attr("src", urls);
		}
	});

</script>
</html>